import 'package:flutter/material.dart';

class CustomAlertDialog extends StatelessWidget {
  final Color backgroundColor;
  final double width;
  final double height;
  final String title;
  final double titleHorizontalPadding;
  final double titleVerticalPadding;
  final TextStyle? titleStyle;
  final Widget content;
  final double contentPadding;
  final double contentTopPadding; // 新增：内容顶部间距
  final AlignmentGeometry contentAlignment;
  final BoxConstraints? contentConstraints;
  final String confirmText;
  final String cancelText;
  final bool showConfirmButton;
  final bool showCancelButton;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;

  const CustomAlertDialog({
    Key? key,
    this.backgroundColor = Colors.white,
    this.width = 300.0,
    this.height = 300.0,
    required this.title,
    this.titleHorizontalPadding = 16.0,
    this.titleVerticalPadding = 12.0,
    this.titleStyle,
    required this.content,
    this.contentPadding = 16.0,
    this.contentTopPadding = 8.0, // 默认值
    this.contentAlignment = Alignment.center,
    this.contentConstraints,
    this.confirmText = '确定',
    this.cancelText = '取消',
    this.showConfirmButton = false,
    this.showCancelButton = false,
    this.onConfirm,
    this.onCancel,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Material(
        color: Colors.transparent,
        child: Container(
          width: width,
          height: height,
          decoration: BoxDecoration(
            color: backgroundColor,
            borderRadius: BorderRadius.circular(10.0),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              // 标题部分
              Padding(
                padding: EdgeInsets.symmetric(
                  horizontal: titleHorizontalPadding,
                  vertical: titleVerticalPadding,
                ),
                child: Text(
                  title,
                  style: titleStyle ?? TextStyle(
                    fontSize: 18.0,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),

              // 分割线
              // Divider(height: 0),

              // 中间内容
              Expanded(
                child: Padding(
                  padding: EdgeInsets.fromLTRB(
                      contentPadding,
                      contentTopPadding, // 使用新参数控制顶部间距
                      contentPadding,
                      contentPadding
                  ),
                  child: ConstrainedBox(
                    constraints: contentConstraints ?? const BoxConstraints(),
                    child: Align(
                      alignment: contentAlignment,
                      child: content,
                    ),
                  ),
                ),
              ),

              // 分割线
              Divider(height: 0),

              // 按钮区域
              if (showConfirmButton || showCancelButton)
                Container(
                  height: 48.0,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      if (showCancelButton)
                        TextButton(
                          onPressed: onCancel ?? () => Navigator.of(context).pop(),
                          child: Text(cancelText),
                        ),
                      if (showConfirmButton)
                        TextButton(
                          onPressed: onConfirm ?? () => Navigator.of(context).pop(),
                          child: Text(confirmText),
                        ),
                    ],
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}